﻿using System;
using System.Linq.Expressions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Collections;
namespace Com.Dal.Cms
{
    /// <summary>
    /// Access  the database base class ,you must implement it;
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IRepository<T> where T: class,new()
    {
        /// <summary>
        /// 构造一个T类型实例
        /// </summary>
        /// <returns></returns>
        T Create();
        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <param name="entity">T类型实例</param>
        /// <returns>T实例</returns>
        T Insert(T entity);
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity">T类型实例</param>
        /// <returns>T实例</returns>
        int Update(T entity);
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Delete(T entity);
        /// <summary>
        /// 查询一条记录
        /// </summary>
        /// <param name="ps">主键值</param>
        /// <returns>T实例</returns>
        T Find(params Object[] ps);
        /// <summary>
        /// 查询一块数据
        /// </summary>
        /// <param name="blockIndex">数据块索引</param>
        /// <param name="blockSize">数据块尺寸(数据条数)</param>
        /// <param name="where">Lambda表达式,表示查询条件</param>
        /// <param name="orderBy">Lambda表达式,表示排序</param>
        /// <param name="isDescending">是否是降序</param>
        /// <returns>结果集合</returns>
        ICollection<T> FindList(int blockIndex, int blockSize, Expression<Func<T, bool>> where,Expression<Func<T,Int32>>orderBy);
        /// <summary>
        /// 根据sql语句查询
        /// </summary>
        /// <param name="sql">参数化的sql语句</param>
        /// <param name="ps">参数键值数组</param>
        /// <returns>CDATA[[ICollection<T>]]</returns>
        ICollection<T> FindList(String sql,params Object []ps);
        /// <summary>
        /// 执行一条参数化的 sql语句
        /// </summary>
        /// <param name="type">返回值的类型</param>
        /// <param name="sql">参数化sql语句</param>
        /// <param name="ps">参数键值</param>
        /// <returns></returns>
        Object ExecuteSql(Type type,String sql, Object[] ps);
    }
}
